<template>
    <div class="login">
        用户名：<input type="text" v-model="userName"/><br>
        密码：<input type="password" v-model="password"/><br>
        <input type="button" value="登陆" @click="login">
    </div>
</template>
<script>
    import {URI_LOGIN} from 'src/const/uri';
    import SHA256 from 'crypto-js/sha256';

    export default {
        name: 'index',
        data() {
            return {
                userName: '',
                password: ''
            }
        },
        methods: {
            login() {
                if (!window.hasOwnProperty('qqlgJsCallNative') && isDebug) {
                    // 调试的时候可以模拟登陆
                    this.$ajax.post(URI_LOGIN, {
                        userName: this.userName,
                        password: SHA256(this.password).toString()
                    }, (res) => {
                        window.localStorage.setItem('qqlgClientAccessToken', res.data.accessToken);
                        window.localStorage.setItem('qqlgClientUserId', res.data.id);
                        window.localStorage.setItem('qqlgClientNickName', res.data.nickName);
                        alert('登录成功');
                    });
                } else {
                    this.$vux.toast.show({
                        text: '请使用客户端登陆'
                    });
                }
            }
        }
    }
</script>
<style lang="less" scoped>
    .login{
        width: 80%;
        margin: 0 auto;
        text-align: center;
        margin-top:1rem;
    }
    input {
        border: 1px solid #dddddd;

    }

</style>
